/**
 * 
 */
package fr.mynounou.web.beans;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.SessionScoped;

import org.apache.log4j.Logger;
import org.primefaces.context.RequestContext;
import org.primefaces.model.DashboardColumn;
import org.primefaces.model.DashboardModel;
import org.primefaces.model.DefaultDashboardColumn;
import org.primefaces.model.DefaultDashboardModel;

import fr.mynounou.web.model.UsersManager;
import fr.mynounou.web.model.dao.UserDao;

/**
 * @author btavernier
 * 
 */
@SuppressWarnings("serial")
@ManagedBean(name = "ParentController")
@SessionScoped
public class ParentController implements Serializable {
	@ManagedProperty(value = "#{UsersManager}")
	private UsersManager usersManager;

	@ManagedProperty(value = "#{UserDAO}")
	private UserDao userDao;

	@ManagedProperty(value = "#{ConnectionController}")
	private ConnectionController connCtrl;

	private ParentsDataModel parents = null;

	/**
	 * @return the usersManager
	 */
	public UsersManager getUsersManager() {
		return usersManager;
	}

	/**
	 * @param usersManager
	 *            the usersManager to set
	 */
	public void setUsersManager(UsersManager usersManager) {
		this.usersManager = usersManager;
	}

	/**
	 * @return the parents
	 */
	public ParentsDataModel getParents() {
		if (parents == null) {
			parents = new ParentsDataModel(userDao.listParents(connCtrl
					.getNounou()));
		}
		return parents;
	}

	/**
	 * @return the userDao
	 */
	public UserDao getUserDao() {
		return userDao;
	}

	/**
	 * @param userDao
	 *            the userDao to set
	 */
	public void setUserDao(UserDao userDao) {
		this.userDao = userDao;
	}

	/**
	 * @return the connCtrl
	 */
	public ConnectionController getConnCtrl() {
		return connCtrl;
	}

	/**
	 * @param connCtrl
	 *            the connCtrl to set
	 */
	public void setConnCtrl(ConnectionController connCtrl) {
		this.connCtrl = connCtrl;
	}

	public void add() {
		Logger.getLogger(getClass()).info("Open dialog");
		Map<String, Object> options = new HashMap<String, Object>();
		options.put("modal", false);
		options.put("draggable", true);
		options.put("resizable", true);
		// hint: available options are modal, draggable, resizable, width,
		// height, contentWidth and contentHeight

		RequestContext.getCurrentInstance().openDialog("faces/add-parents",
				options, null);

	}

}
